package com.bh.weapp.controller.customer;

import com.bh.common.annotation.Log;
import com.bh.common.core.controller.BaseController;
import com.bh.common.core.domain.AjaxResult;
import com.bh.common.enums.BusinessType;
import com.bh.extend.convert.JcLedEvaluationConvert;
import com.bh.extend.domain.JcLedEvaluation;
import com.bh.extend.service.IJcLedEvaluationService;
import com.bh.extend.vo.JcLedEvaluationAddVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 订单评价Controller
 *
 * @author slx
 * @date 2023-03-26
 */
@Api(tags = {"CUST订单评价API"})
@RestController
@RequestMapping("/api/cust/extend/orderEvaluation")
public class JcLedEvaluationCustApiController extends BaseController {

    @Autowired
    private IJcLedEvaluationService jcLedEvaluationService;
    @Autowired
    private JcLedEvaluationConvert jcLedEvaluationConvert;

    /**
     * 新增保存订单评价
     */
    @Transactional(rollbackFor = Exception.class)
    @ApiOperation("新增保存订单评价")
    @Log(title = "订单评价", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult addSave(@RequestBody @Validated JcLedEvaluationAddVo jcLedEvaluationVo) {
        // 只做新增，不做订单相关的状态变化
        JcLedEvaluation jcLedEvaluation = jcLedEvaluationConvert.toDO(jcLedEvaluationVo);
        return toAjax(jcLedEvaluationService.insertJcLedEvaluation(jcLedEvaluation));
    }

    /**
     * 修改订单评价
     */
    @ApiOperation("查询订单评价")
    @GetMapping("/getInfo/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId) {
        JcLedEvaluation jcLedEvaluation = jcLedEvaluationService.selectJcLedEvaluationByOrderId(orderId);
        return AjaxResult.success(jcLedEvaluation);
    }
}
